// PurchaseServiceImpl.java - 服务实现
package com.example.electricbicycle.service;

import com.example.electricbicycle.dao.PurchaseDAO;
import com.example.electricbicycle.dao.PurchaseDAOImpl;
import com.example.electricbicycle.po.PurchaseOrder;
import com.example.electricbicycle.po.Vehicle;
import java.util.List;

public class PurchaseServiceImpl implements PurchaseService {
    private PurchaseDAO purchaseDAO = new PurchaseDAOImpl();

    @Override
    public boolean createPurchaseOrder(PurchaseOrder order) {
        return purchaseDAO.addPurchaseOrder(order);
    }

    @Override
    public boolean updatePurchaseOrder(PurchaseOrder order) {
        return purchaseDAO.updatePurchaseOrder(order);
    }

    @Override
    public boolean deletePurchaseOrder(int orderId) {
        return purchaseDAO.deletePurchaseOrder(orderId);
    }

    @Override
    public PurchaseOrder getPurchaseOrderById(int orderId) {
        return purchaseDAO.getPurchaseOrderById(orderId);
    }

    @Override
    public List<PurchaseOrder> getSalesmanPurchaseOrders(int salesmanId) {
        return purchaseDAO.getPurchaseOrdersBySalesman(salesmanId);
    }

    @Override
    public boolean canEditOrder(int orderId) {
        return purchaseDAO.isOrderEditable(orderId);
    }


    @Override
    public Vehicle getVehicleById(int id) {
        return purchaseDAO.getVehicleById(id);
    }

    @Override
    public int getTotalOrderCount(int salesmanId) {
        try {
            return purchaseDAO.getTotalOrderCount(salesmanId);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int getPendingOrderCount(int salesmanId) {
        try {
            return purchaseDAO.getPendingOrderCount(salesmanId);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int getApprovedOrderCount(int salesmanId) {
        try {
            return purchaseDAO.getApprovedOrderCount(salesmanId);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public List<PurchaseOrder> getFilteredOrders(int salesmanId, String type) {
        try {
            return purchaseDAO.getFilteredOrders(salesmanId, type);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public List<PurchaseOrder> getAllOrdersForSalesman(int salesmanId) {
        return purchaseDAO.getAllOrdersForSalesman(salesmanId);
    }
    @Override
    public boolean createVehicle(Vehicle vehicle) {
        return purchaseDAO.addVehicle(vehicle);
    }


    @Override
    public boolean updateVehicle(Vehicle vehicle) {
        return purchaseDAO.updateVehicle(vehicle);
    }

    @Override
    public boolean deleteVehicle(int vehicleId) {
        return purchaseDAO.deleteVehicle(vehicleId);
    }

    @Override
    public List<Vehicle> getAllVehicles() {
        return purchaseDAO.getAllVehicles();
    }


}